<?php

namespace app\admin\controller;

use think\Loader;

class Statistic extends Common {

    public function _initialize(){

        $this->statistic = new \app\admin\model\Statistic();
    }

    //统计
    public function index() {

        $list = null;
        $list = $this->statistic->statisticList();
        $cl = [];
        $cl = $this->statistic->sumCLl();
        $this->assign('list', $list);
        $this->assign('cl', $cl);
        return $this->fetch();
    }

    //增加
    public function addp() {

        $data = input();
        $daArr = [];
        if($data['sta_id']){
            if( $data['platform_type']=='gdp'){

                $daArr = $this->statistic->statisticDetail(['sta_id'=>$data['sta_id']]);
            }else{
                $this->error('错误操作', url('index'));
            }
        }
        $quarter = [
            0=>['name'=>'第一季度','val'=>1],
            1=>['name'=>'第二季度','val'=>2],
            2=>['name'=>'第三季度','val'=>3],
            3=>['name'=>'第四季度','val'=>4],
        ];
        $time = date('Y', time());
        $year[0] = $time-1;
        $year[1] = $time;
        $year[2] = $time+1;
        $this->assign('quarter', $quarter);
        $this->assign('year', $year);
        $this->assign('info', $daArr);
        return $this->fetch();
    }

    //增加
    public function add() {

        $data = input();
        if($data['id']){

            $id = $data['id'];
        }else{
            
            $id = null;
        }

        $arr = [];
        $arr['platform_name'] = 'GDP';
        $arr['platform_type'] = 'gdp';
        $arr['year'] = $data['year'];
        $arr['num'] = $data['quarter'];
        $arr['val'] = $data['gdp'];
        $this->statistic->saveGdp($id, $arr);
        $this->success('操作成功', url('index'));
    }

    //删除
    public function del() {

        $data = input();
        $this->securitie->securitieInfoUpdate($data['sid'], $data['stock_code'],['status'=>$data['status']]);
        $this->success('操作成功', url('index'));
    }

    //修改
    public function updateSecurity() {

        $data = input();
        $this->statistic->updateSecurityData($data);
        $this->success('操作成功', url('index'));
    }

    //修改
    public function gdpUpdateSecurity() {

        $data = input();
        if($data['sta_id']){

            $arr = [];
            $arr['year'] = $data['year'];
            $arr['num'] = $data['quarter'];
            $arr['val'] = $data['gdp'];

            $this->statistic->saveGdp($data['sta_id'], $arr);
            $this->success('操作成功', url('index'));
        }else{
            $this->error('编辑错误', url('index'));
        }
    }
}